// 存储各个组件的生命周期钩子
const lifecycleHooks: Record<string, Array<Function>> = {
  mounted: [],
  updated: [],
  unmounted: [],
};

export function onMounted(fn: () => void) {
  lifecycleHooks.mounted.push(fn);
}

export function onUpdated(fn: () => void) {
  lifecycleHooks.updated.push(fn);
}

export function onUnmounted(fn: () => void) {
  lifecycleHooks.unmounted.push(fn);
}

// 触发生命周期钩子：组件挂载
export function callMounted() {
  lifecycleHooks.mounted.forEach((fn) => fn());
}

// 触发生命周期钩子：组件更新
export function callUpdated() {
  lifecycleHooks.updated.forEach((fn) => fn());
}

// 触发生命周期钩子：组件卸载
export function callUnmounted() {
  lifecycleHooks.unmounted.forEach((fn) => fn());
}
